401 error on twitter streaming API with python

by: anoopdcs, 7 years ago

Last edited: 7 years ago

I am using Twitter API and python for grab the streaming data from twitter. then I got the  error 401.

My ubuntu machine time zone is : GMT 5.30, India
My twitter account time zone also: GMT 5.30, India

Please help me to resolve this.
My code is pasted bellow..

-- Thank you

####################################################3
consumer_key = " "
consumer_secret = " "
access_key = " "
access_secret = " "
#Twitter only allows access to a users most recent 3240 tweets with this method
#authorize twitter, initialize tweepy


class StdOutListener(StreamListener):
def on_data(self, data):
print data
return True

def on_error(self,status):
print status


if __name__ == '__main__':
l = StdOutListener()
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
stream = Stream(auth,l)
#api = tweepy.API(auth)
stream.filter(track=['car'])

#########################################################



You must be logged in to post. Please login or register an account.



You can learn more about the Twitter API error codes here: https://dev.twitter.com/overview/api/response-codes

The 401 is for unauthorized. If you are getting this always, chances are, you typoed or incorrectly did your credentials. You can also get a 401 for restarting your script too often (basically for reconnecting too much to the stream API). You might also have some sort of proxy issue, or something else I am not thinking of at the moment. Good luck!

-Harrison 7 years ago

You must be logged in to post. Please login or register an account.


Thank you sir,
I successfully worked with my credential when reading tweets of individual users using their username.
But when moving into the streaming process it shows the 401 error.
Here in our University, we have a main gateway server and firewall system, all our computer network connections are monitored by them. Sir did I need to check there for any kind of permission from the firewall.
Please help me.

-anoopdcs 7 years ago

You must be logged in to post. Please login or register an account.


I really cannot answer that for you, try testing it on a different network and see if it works.

-Harrison 7 years ago

You must be logged in to post. Please login or register an account.

Hey,

Did you manage to solve this issue? I am facing the exact same prob as you have mentioned. Any help is solicited.

-aayushikuls1 7 years ago

You must be logged in to post. Please login or register an account.